<template>
  <div class="site-wrapper site-page--login">
    <div class="site-content">
      <div class="welcome-title">
        <div class="c-flex c-flex-col c-flex-jus-center c-flex-item-center">
            <label>欢迎使用安荣货运管理系统</label>
<!--          <img  src="~@/assets/img/login/login-title-1.png" alt="">-->
<!--          <img src="~@/assets/img/login/login-title-2.png" alt="">-->
        </div>
      </div>
      <div class="login-main">
        <h3 class="login-title c-flex c-flex-jus-center c-flex-item-center">
          <img src="~@/assets/img/login/login-left-arrow.png" alt="">
          系统登录
          <img src="~@/assets/img/login/login-right-arrow.png" alt="">
        </h3>
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" status-icon>
          <el-form-item prop="userName">
            <el-input v-model="dataForm.userName" placeholder="帐号">
              <img class="account" slot="prefix" src="~@/assets/img/login/login-account.png"/>
            </el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input v-model="dataForm.password" type="password" placeholder="密码">
              <img class="account" slot="prefix" src="~@/assets/img/login/login-pwd.png"/>
            </el-input>
          </el-form-item>
          <el-form-item prop="captcha">
            <el-row :gutter="20">
              <el-col :span="14">
                <el-input v-model="dataForm.captcha" placeholder="验证码">
                  <img class="account" slot="prefix" src="~@/assets/img/login/login-code.png"/>
                </el-input>
              </el-col>
              <el-col :span="10" class="login-captcha">
                <img :src="captchaPath" @click="getCaptcha()" alt="">
              </el-col>
            </el-row>
          </el-form-item>
          <el-form-item>
            <el-button class="login-btn-submit" type="primary" @click="dataFormSubmit()">登录</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import { getUUID } from '@/utils'
export default {
  data () {
    return {
      dataForm: {
        userName: '',
        password: '',
        uuid: '',
        captcha: ''
      },
      dataRule: {
        userName: [
          { required: true, message: '帐号不能为空', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '密码不能为空', trigger: 'blur' }
        ],
        captcha: [
          { required: true, message: '验证码不能为空', trigger: 'blur' }
        ]
      },
      captchaPath: ''
    }
  },
  created () {
    this.getCaptcha()
  },
  methods: {
    // 提交表单
    dataFormSubmit () {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl('/sys/login'),
            method: 'post',
            data: this.$http.adornData({
              'username': this.dataForm.userName,
              'password': this.dataForm.password,
              'uuid': this.dataForm.uuid,
              'captcha': this.dataForm.captcha,
              'userType':1
            })
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$cookie.set('token', data.token)

              this.$router.replace({ name: 'home' })
            } else {
              this.getCaptcha()
              this.$message.error(data.msg)
            }
          })
        }
      })
    },
    // 获取验证码
    getCaptcha () {
      this.dataForm.uuid = getUUID()
      this.captchaPath = this.$http.adornUrl(`/captcha.jpg?uuid=${this.dataForm.uuid}`)
    }
  }
}
</script>
<style lang="scss" scoped>
.site-wrapper.site-page--login {
  overflow: hidden;width:100%;height:100%;
  background-image: url(~@/assets/img/login/login-bg.png);
  background-size: 100% 100%;
  .site-content {min-height: 100%; }
  .welcome-title{
    margin-top: 210px;
    img:first-child{width: 537px;height: 33px;margin-bottom:16px;}
    img:last-child{width: 351px;height: 19px;}
    label{
      font-size: 35px;
      font-family: "Al Bayan";
      font-weight: bold;
      color: white;
    }
  }
  .login-main {
    margin: 20px auto 0;
    padding: 8px 50px;
    width: 538px;
    height:430px;
    background-image: url(~@/assets/img/login/login-border-bg.png);
    background-size: 538px 430px;
    background-repeat: no-repeat;
  }
  .login-title {
    font-size: 24px; font-family: PingFang SC;font-weight: 500;color: #FFFFFF;
    background: linear-gradient(179deg, #EBFFFF 0%, #6EB1E6 100%);gap: 6px;
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    img{width: 58px;height: 14px;}
  }
  .login-captcha {
    overflow: hidden;
    > img {
      width: 100%;
      cursor: pointer;
    }
  }
  .login-btn-submit {
    width: 100%;height: 49px;background: linear-gradient(179deg, #4990D2, #0F4D82);
  }
  .account{width: 18px; height: 18px;}
  /deep/.el-input__inner{
    background:rgba(6,135,205,0.3);border: 1px solid #1475B7;color: #ffffff;
  }
  /deep/.el-input__prefix{left: 10px;}
  /deep/.el-button--primary{border:none;}
}
</style>
